﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class PeiSong : System.Web.UI.Page
{
    public string Title, Keywords, Description, p_Title, p_Amount, p_Packing, p_ProImg, p_Specifications, p_EndTime, p_Content, p_Contacts, p_Tel, p_Phone, p_Fax, p_Email, p_Website, p_Address, Prices;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            WebSiteInfo();
            ps_pro();
        }
    }
    public void WebSiteInfo()
    {
        DataTable dt = Class1.ExecSel("select WS_Title,WS_keywords,WS_description from Site_Config");
        this.Title = Convert.ToString(dt.Rows[0]["WS_Title"]);
        this.Keywords = Convert.ToString(dt.Rows[0]["WS_keywords"]);
        this.Description = Convert.ToString(dt.Rows[0]["WS_description"]);
    }
    public void ps_pro()
    {
        int ID = int.Parse(Request.QueryString["p_ID"]);
        string SQL = "select * from Delivery where p_Lock=0 and p_ID=" + ID + " order by p_ID desc";
        DataTable dt = Class1.ExecSel(SQL);
        p_Title = dt.Rows[0]["p_Title"].ToString();
        p_Amount = dt.Rows[0]["p_Amount"].ToString();
        p_Packing = dt.Rows[0]["p_Packing"].ToString();
        if (dt.Rows[0]["p_ProImg"].ToString() != "" && dt.Rows[0]["p_ProImg"].ToString() != null)
        {
            p_ProImg = "<a href='#' target=_blank><img src=" + dt.Rows[0]["p_ProImg"].ToString().Trim() + " border=0 width=220 height=220 /></a>";
        }
        p_Specifications = dt.Rows[0]["p_Specifications"].ToString();
        p_Content = dt.Rows[0]["p_Content"].ToString();
        p_Contacts = dt.Rows[0]["p_Contacts"].ToString();
        p_Tel = dt.Rows[0]["p_Tel"].ToString();
        p_Phone = dt.Rows[0]["p_Phone"].ToString();
        p_Fax = dt.Rows[0]["p_Fax"].ToString();
        p_Email = dt.Rows[0]["p_Email"].ToString();
        p_Website = dt.Rows[0]["p_Website"].ToString();
        p_Address = dt.Rows[0]["p_Address"].ToString();
        Prices = dt.Rows[0]["p_Prices"].ToString();

        int a = int.Parse(dt.Rows[0]["p_EndTime"].ToString());
        DateTime EndTime = DateTime.Now;
        EndTime = EndTime.AddDays(a);
        p_EndTime = EndTime.ToString();

        SQL = ("update Delivery set p_Hits=p_Hits+1 where p_ID=" + ID);
        Class1.ExecSql(SQL);

    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DateTime G_Time=DateTime.Now;
        int G_ID = int.Parse(Request.QueryString["p_ID"]);
        string SQL = "select * from Delivery where p_Lock=0 and p_ID=" + G_ID + " order by p_ID desc";
        DataTable dt0 = Class1.ExecSel(SQL);
        p_Title = dt0.Rows[0]["p_Title"].ToString();
        Prices = dt0.Rows[0]["p_Prices"].ToString();
        string p_b = dt0.Rows[0]["p_b_ID"].ToString();
        string p_z = dt0.Rows[0]["p_z_ID"].ToString();
        DataTable dt1 = Class1.ExecSel("select  * from PsClass where  Menu_ID=" + p_b + "");
        DataTable dt2 = Class1.ExecSel("select  * from PsClass where  Menu_ID=" + p_z + "");
        string ppd = dt1.Rows[0]["Menu_Name"].ToString();
        string ppx = dt2.Rows[0]["Menu_Name"].ToString();

        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            string G_User = Session["wj_User"].ToString();
            string USQL = "select wj_User,wj_ID from wj_User where wj_User='" + G_User + "'";
            DataTable dt = Class1.ExecSel(USQL);

            string usql = "select count(*) from Cart where G_PID='" + G_ID + "' and G_UID='" + dt.Rows[0]["wj_ID"].ToString() + "'";
            int i = int.Parse(Class1.SelOne(usql));
            if (i == 0)
            {

                string GSql = "insert into Cart(G_UID,G_PID,G_D,G_X,G_TITLE,G_PRICES,G_Time,G_TOTAL)values('" + dt.Rows[0]["wj_ID"].ToString() + "','" + G_ID + "','" + ppd + "','" + ppx + "','" + p_Title + "','" + Prices + "','" + G_Time + "','" + Prices + "')";
                Class1.ExecSql(GSql);
                Response.Redirect("wjCart.aspx");
            }
            else
            {
                string HSQL = ("update Cart set G_AMOUNT=G_AMOUNT+1,G_TOTAL=G_PRICES+G_PRICES where G_PID=" + G_ID);
                Class1.ExecSql(HSQL);
                Response.Redirect("wjCart.aspx");
            }
            
        }
    }
}
